package com.vvv.designpattern.service;

import com.vvv.designpattern.bridge.abst.AbstractRegisterLoginComponent;
import com.vvv.designpattern.bridge.abst.factory.RegisterLoginComponentFactory;
import com.vvv.designpattern.pojo.UserInfo;
import com.vvv.designpattern.repo.UserRepository;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author vvv
 * @date 2023-11-14 15 11
 * discription
 * 这里直接去调用AbstractRegisterLoginComponent的抽象方法，现在的问题是如何获得AbstractRegisterLoginComponent的实现类
 * 1. 直接new X 这样每个用户线程来都要去创建两个对象
 * 2. 将RegisterLoginComponent注册成bean X 这样在RegisterLoginComponent中
 *      spring不知道你要注册的是哪个对象（是RegisterLoginByDefault呢？还是ByGitee）
 * 所以我们需要建一个工程类，去把左路的实现类和右路的实现类的生成和缓存，然后通过type参数去获得对应的对象
 *
 */
@Service
public class UserBridgeService {

    public String login(String account, String password) {
        AbstractRegisterLoginComponent component = RegisterLoginComponentFactory.getComponent("Default");
        return component.login(account, password);
    }

    public String register(UserInfo userInfo) {
        AbstractRegisterLoginComponent component = RegisterLoginComponentFactory.getComponent("Default");
        return component.register(userInfo);
    }

    public String login3rd(HttpServletRequest request, String type) {
        AbstractRegisterLoginComponent component = RegisterLoginComponentFactory.getComponent(type);
        return component.login3rd(request);
    }
}
